import axios from 'axios'
import Vue from "vue";
const hcvue = new Vue();

export default{
	//模板下载
	downLoad(item) {
		let headers = {
			 'TOKEN':sessionStorage.getItem('token')
		}; 
		let params = {
			  fileName: item.fileName,//文件名
			  url:item.url,//接口地址
		}
		  axios({method: 'get', url: item.url,headers:headers,responseType: 'blob'}).then(res => {
			  console.log(res)
				if (!res.data) {
				  return;
				}
				if ("download" in document.createElement("a")) {
				  let url = window.URL.createObjectURL(new Blob([res.data]));
				  let link = document.createElement("a");
				  link.style.display = "none";
				  link.href = url;
				  link.setAttribute("download", params.fileName);
				  document.body.appendChild(link);
				  link.click();
				} else {
				  navigator.msSaveBlob(new Blob([res.data]), params.fileName);
				}
		  })
	 },
     //附件下载
	 fileDownload(item){
		let headers = {
			 'TOKEN':sessionStorage.getItem('token')
		}; 
		let params = {
			filePath: item.filePath,//附件返回的地址
			fileName: item.fileName,//附件名
		}
		axios({method: 'post', url: '/member-security/file/fileDownloadCommon', headers:headers ,data: params, responseType: 'blob'}).then(res => {
				if (!res.data) {
				return;
				}
				if ("download" in document.createElement("a")) {
				let url = window.URL.createObjectURL(new Blob([res.data]));
				let link = document.createElement("a");
				link.style.display = "none";
				link.href = url;
				link.setAttribute("download", params.fileName);
				document.body.appendChild(link);
				link.click();
				} else {
				navigator.msSaveBlob(new Blob([res.data]), params.fileName);
				}
		})
	  },
	}
	 

